package test.list;

import java.util.ArrayDeque;
import java.util.Queue;

public class MyQueue {
    int head = 0;
    int tail = 0;
    int size = 0;
    int capacity = 0;
    int[] queue;
    public MyQueue(int k) {
        queue = new int[k];
        capacity = k;
    }

    public boolean enQueue(int value) {
        if(size != capacity){
            queue[tail] = value;
            if(tail == capacity - 1){
                tail = 0;
            }else{
                tail++;
            }
            size++;
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(size != 0){
            if(head == capacity - 1){
                head = 0;
            }else{
                head++;
            }
            size--;
            return true;
        }
        return false;
    }

    public int Front() {
        if(size == 0){
            return -1;
        }
        return queue[head];
    }

    public int Rear() {
        if(size == 0){
            return -1;
        }
        if(tail == 0){
            return queue[capacity - 1];
        }
        return queue[tail - 1];
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == capacity;
    }
}
